<?php
/**
 * Created by PhpStorm.
 * User: mac
 * Date: 2018/6/25
 * Time: 09:37
 */

namespace app\common\model;


use think\Model;

class MyCourse extends Model
{
    //根据用户ID获取该用户的全部课程
    public function getMyCourseById($id,$page,$pageSize = 10){
        if(!$id && !is_numeric($id)){
            exception("传递的ID不合法");
        }

        $where = array(
            'mc.user_id' => $id,
            'mc.status' => 1,
        );

        $offset = ($page - 1) * $pageSize;


        return $this->alias("mc")->join("xm_courses c","mc.course_id=c.id")->join("xm_author a","c.author_id=a.id")->where($where)->field("c.title,c.img_url,c.id,a.name,mc.browse")->limit($offset,$pageSize)->select();
    }

    //根据用户ID获取该用户的课程数量
    public function getMyCourseCountById($id){
        if(!$id && !is_numeric($id)){
            exception("传递的ID不合法");
        }

        $where = array(
            'mc.user_id' => $id,
            'mc.status' => 1,
        );

        return $this->alias("mc")->join("xm_courses c","mc.course_id=c.id")->join("xm_author a","c.author_id=a.id")->where($where)->count();

    }
}